Fix timezone issue when calculating min/max values in tibber #14009#14080
Fix timezone issue when calculating min/max values in tibber #14009#14080MartinHjelmare merged 2 commits intodevfrom
Conversation
| if (not self._newest_data_timestamp or | ||
| (self._newest_data_timestamp - now).total_seconds()/3600 < 12 | ||
| if (not self._last_data_timestamp or | ||
| (self._last_data_timestamp - now).total_seconds()/3600 < 12 |
There was a problem hiding this comment.
Why is the check < 12? That looks like the opposite of what I would expect.
There was a problem hiding this comment.
The data change every hour, but is available 12-36 hours ahead. So when we have less then 12 hours of future data available new data should be available. We do not know exactly when the new is available, so we might need to retry.
| now = dt_util.now() | ||
| if self._tibber_home.current_price_total and self._last_updated and \ | ||
| self._last_updated.hour == now.hour and self._newest_data_timestamp: | ||
| self._last_updated.hour == now.hour and self._last_data_timestamp: |
There was a problem hiding this comment.
Why shouldn't we let the scan interval decide on the update frequency?
There was a problem hiding this comment.
The data change every hour, but we want to retry if no data are available.
There was a problem hiding this comment.
If the data hasn't changed since last update, making a state update will not write a new state to the state machine. So you could just try to do that without making the check here. Are there any downsides, you think? It would make the code cleaner.
There was a problem hiding this comment.
I am not sure I understood your last comment.
But if I do not return here, the _update_current_price will be called every minute
There was a problem hiding this comment.
Yes, and if all values including state and state attributes remain the same a call to do a state update, will not write a new state to the state machine, so will not clog the database.
The only thing that seems to change, while fetched data is the same, is the time_diff variable that is computed from the current time of the call. What will happen there?
There was a problem hiding this comment.
Yes, there will be no state change and no new state to the state machine.
But I though it would be good avoid calling _update_current_price each minute, and then also avoid iterate over all prices each minute.
So the return here is only to avoid unnecessary cpu load.
MartinHjelmare
left a comment
There was a problem hiding this comment.
Looks good to me. My comment about possible clean up, if makes sense, is for another PR.
Description:
fix timezone issue when calculating min/max values in tibber #14009
Related issue (if applicable): fixes #14009
Checklist:
tox. Your PR cannot be merged unless tests pass